package com.wl.zk.onoffline;

import org.I0Itec.zkclient.ZkClient;

public class Server {

    ZkClient zkClient = null;
    private void getClient(){
        zkClient = new ZkClient("linux121:2181,linux122:2181,linux123:2181");

        if(!zkClient.exists("/servers")){
            zkClient.createPersistent("/servers");
        }
    }

    private void saveServerInfo(String ip,String port){
        String sequentialpath = zkClient.createEphemeralSequential("/servers/server", ip + ":" + port);

        System.out.println("---->>> 服务器器注册成功， ip="+ip+";port ="+port+";节点路路径信息="+sequentialpath);
    }

    public static void main(String[] args) {
        Server server = new Server();
        server.getClient();
        server.saveServerInfo(args[0],args[1]);

        new TimeServer(Integer.parseInt(args[1])).start();
    }

}
